using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLMDESSK
    {
        public DataRow Convert2LMDESSK(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLMDESSK(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LMDMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LMDKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["LMDDESS"] = " ".PadRight(10 ); 
         dwReturn["LMDMTYP"] = " ".PadRight(8 ); 
         dwReturn["LMDDSTA"] = " ".PadRight(1 ); 
         dwReturn["LMDSTGRD"] = " ".PadRight(3 ); 
         dwReturn["LMDNAME"] = " ".PadRight(20 ); 
         dwReturn["LMDEXCLKZ"] = " ".PadRight(1 ); 
         dwReturn["LMDDRBRT"] = " ".PadRight(0 ); 
         dwReturn["LMDANZBA"] = " ".PadRight(0 ); 
         dwReturn["LMDRAPPH"] = " ".PadRight(0 ); 
         dwReturn["LMDRAPPB"] = " ".PadRight(0 ); 
         dwReturn["LMDRANDL"] = " ".PadRight(0 ); 
         dwReturn["LMDRANDR"] = " ".PadRight(0 ); 
         dwReturn["LMDVERSL"] = " ".PadRight(0 ); 
         dwReturn["LMDVERSQ"] = " ".PadRight(0 ); 
         dwReturn["LMDBEM"] = " ".PadRight(50 ); 
         dwReturn["LMDTXTKZ"] = " ".PadRight(1 ); 
         dwReturn["LMDANZSCH"] = " ".PadRight(0 ); 
         dwReturn["LMDAMOMTR"] = " ".PadRight(0 ); 
         dwReturn["LMDFILLER"] = " ".PadRight(48 ); 
         dwReturn["LMDAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LMDAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LMDAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LMDNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["LMDNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLMDESSK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLMDESSK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLMDESSK(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLMDESSK(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLMDESSK(dwLocal, ITXDBVERSION);
            }
            UpdateLMDESSK(dwLocal);
        }
        public void InsertLMDESSK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LMDESSK(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLMDESSK(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LMDESSK WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LMDESSK  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LMDESSK";
            Return = Result;
            return Return;
        }
        public void DeleteLMDESSK(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LMDESSK   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLMDESSK(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LMDESSK SET "
                    +"LMDMANDANT= :LMDMANDANT,"
                    +"LMDKUNDNR= :LMDKUNDNR,"
                    +"LMDDESS= :LMDDESS,"
                    +"LMDMTYP= :LMDMTYP,"
                    +"LMDDSTA= :LMDDSTA,"
                    +"LMDSTGRD= :LMDSTGRD,"
                    +"LMDNAME= :LMDNAME,"
                    +"LMDEXCLKZ= :LMDEXCLKZ,"
                    +"LMDDRBRT= :LMDDRBRT,"
                    +"LMDANZBA= :LMDANZBA,"
                    +"LMDRAPPH= :LMDRAPPH,"
                    +"LMDRAPPB= :LMDRAPPB,"
                    +"LMDRANDL= :LMDRANDL,"
                    +"LMDRANDR= :LMDRANDR,"
                    +"LMDVERSL= :LMDVERSL,"
                    +"LMDVERSQ= :LMDVERSQ,"
                    +"LMDBEM= :LMDBEM,"
                    +"LMDTXTKZ= :LMDTXTKZ,"
                    +"LMDANZSCH= :LMDANZSCH,"
                    +"LMDAMOMTR= :LMDAMOMTR,"
                    +"LMDFILLER= :LMDFILLER,"
                    +"LMDAENDZL= :LMDAENDZL,"
                    +"LMDAENDBEN= :LMDAENDBEN,"
                    +"LMDAENDDAT= :LMDAENDDAT,"
                    +"LMDNEUBEN= :LMDNEUBEN,"
                    +"LMDNEUDAT= :LMDNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LMDMANDANT", OracleType.NVarChar).Value = dwData["LMDMANDANT"].ToString(); 
          or1.Parameters.Add("LMDKUNDNR", OracleType.NVarChar).Value = dwData["LMDKUNDNR"].ToString(); 
          or1.Parameters.Add("LMDDESS", OracleType.NVarChar).Value = dwData["LMDDESS"].ToString(); 
          or1.Parameters.Add("LMDMTYP", OracleType.NVarChar).Value = dwData["LMDMTYP"].ToString(); 
          or1.Parameters.Add("LMDDSTA", OracleType.NVarChar).Value = dwData["LMDDSTA"].ToString(); 
          or1.Parameters.Add("LMDSTGRD", OracleType.NVarChar).Value = dwData["LMDSTGRD"].ToString(); 
          or1.Parameters.Add("LMDNAME", OracleType.NVarChar).Value = dwData["LMDNAME"].ToString(); 
          or1.Parameters.Add("LMDEXCLKZ", OracleType.NVarChar).Value = dwData["LMDEXCLKZ"].ToString(); 
          or1.Parameters.Add("LMDDRBRT", OracleType.NVarChar).Value = dwData["LMDDRBRT"].ToString(); 
          or1.Parameters.Add("LMDANZBA", OracleType.NVarChar).Value = dwData["LMDANZBA"].ToString(); 
          or1.Parameters.Add("LMDRAPPH", OracleType.NVarChar).Value = dwData["LMDRAPPH"].ToString(); 
          or1.Parameters.Add("LMDRAPPB", OracleType.NVarChar).Value = dwData["LMDRAPPB"].ToString(); 
          or1.Parameters.Add("LMDRANDL", OracleType.NVarChar).Value = dwData["LMDRANDL"].ToString(); 
          or1.Parameters.Add("LMDRANDR", OracleType.NVarChar).Value = dwData["LMDRANDR"].ToString(); 
          or1.Parameters.Add("LMDVERSL", OracleType.NVarChar).Value = dwData["LMDVERSL"].ToString(); 
          or1.Parameters.Add("LMDVERSQ", OracleType.NVarChar).Value = dwData["LMDVERSQ"].ToString(); 
          or1.Parameters.Add("LMDBEM", OracleType.NVarChar).Value = dwData["LMDBEM"].ToString(); 
          or1.Parameters.Add("LMDTXTKZ", OracleType.NVarChar).Value = dwData["LMDTXTKZ"].ToString(); 
          or1.Parameters.Add("LMDANZSCH", OracleType.NVarChar).Value = dwData["LMDANZSCH"].ToString(); 
          or1.Parameters.Add("LMDAMOMTR", OracleType.NVarChar).Value = dwData["LMDAMOMTR"].ToString(); 
          or1.Parameters.Add("LMDFILLER", OracleType.NVarChar).Value = dwData["LMDFILLER"].ToString(); 
          or1.Parameters.Add("LMDAENDZL", OracleType.NVarChar).Value = dwData["LMDAENDZL"].ToString(); 
          or1.Parameters.Add("LMDAENDBEN", OracleType.NVarChar).Value = dwData["LMDAENDBEN"].ToString(); 
          or1.Parameters.Add("LMDAENDDAT", OracleType.NVarChar).Value = dwData["LMDAENDDAT"].ToString(); 
          or1.Parameters.Add("LMDNEUBEN", OracleType.NVarChar).Value = dwData["LMDNEUBEN"].ToString(); 
          or1.Parameters.Add("LMDNEUDAT", OracleType.NVarChar).Value = dwData["LMDNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
